package com.study.listener;

import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

/**
 * 接收消息
 */
@Component
@Slf4j
public class TopicListener {

    @RabbitListener(queues = "study.topic1")
    public void directQueue1(String s) throws InterruptedException {
        System.out.println("message---topic1---:"+s);
        Thread.sleep(20);
    }

    @RabbitListener(queues = "study.topic2")
    public void directQueue2(String s) throws InterruptedException {
        System.err.println("message---topic2---:"+s);
        Thread.sleep(20);
    }

    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(name = "config.topic.queue1",declare = "true"),
            exchange = @Exchange(name = "config.topic.exchange",type = ExchangeTypes.TOPIC),
            key = {"#.com","com.#"}
    ))
    public void topicQueueConfig1(String s) throws InterruptedException {
        System.out.println("config---topic1---:"+s);
        Thread.sleep(20);
    }

    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(name = "config.topic.queue2",declare = "true"),
            exchange = @Exchange(name = "config.topic.exchange",type = ExchangeTypes.TOPIC),
            key = "#.cn"
    ))
    public void topicQueueConfig2(String s) throws InterruptedException {
        System.out.println("config---topic2---:"+s);
        Thread.sleep(20);
    }
}
